home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / UNIX.ZIP / GUESS / FC.ASM < prev    next >
Assembly Source File  |  1991-11-04  |  15KB  |  892 lines

  1.         ;*****************************************************
  2.     ;
  3.         ;         Fast DES routines
  4.     ;    - Copyright 1991, Christian Beaumont
  5.     ;
  6.     ;
  7.     ;   This program is free software; you can
  8.     ;   redistribute it and/or modify it as you see fit.
  9.     ;
  10.     ;   This program is distributed in the hope that it
  11.     ;   will be useful, but WITHOUT ANY WARRANTY; without
  12.     ;   even the implied warranty of MERCHANTABILITY or
  13.     ;   FITNESS FOR A PARTICULAR PURPOSE.
  14.     ;
  15.     ;*****************************************************
  16.  
  17.                 Locals
  18.  
  19.         .Model    Small,C
  20.  
  21.         .Data
  22.  
  23.         Public    FP
  24.         
  25.         ;******************************************
  26.         ;               -1
  27.         ; Final Permutation FP = IP
  28.         ;
  29. FP        db    39, 7,47,15,55,23,63,31
  30.         db    38, 6,46,14,54,22,62,30
  31.         db    37, 5,45,13,53,21,61,29
  32.         db    36, 4,44,12,52,20,60,28
  33.         db    35, 3,43,11,51,19,59,27
  34.         db    34, 2,42,10,50,18,58,26
  35.         db    33, 1,41, 9,49,17,57,25
  36.         db    32, 0,40, 8,48,16,56,24
  37.         ;
  38.         ;******************************************
  39.  
  40.  
  41.         Public    PC1_C,PC1_D
  42.  
  43.         ;******************************************
  44.         ;
  45.         ; Permuted choice 1 from key bits
  46.         ; to yield C and D.
  47.         ; Parity check bits left out
  48.         ;
  49. PC1_C        db    57,49,41,33,25,17, 9
  50.         db     1,58,50,42,34,26,18
  51.         db    10, 2,59,51,43,35,27
  52.         db    19,11, 3,60,52,44,36
  53.         ;
  54. PC1_D        db    63,55,47,39,31,23,15
  55.         db     7,62,54,46,38,30,22
  56.         db    14, 6,61,53,45,37,29
  57.         db    21,13, 5,28,20,12, 4
  58.         ;
  59.         ;******************************************
  60.  
  61.  
  62.         Public    PC2_C,PC2_D
  63.  
  64.         ;******************************************
  65.         ;
  66.         ; Permuted choice 2, to pick out the bits
  67.         ; from the CD array that generates the key
  68.         ;
  69. PC2_C        db    14,17,11,24, 1, 5
  70.         db     3,28,15, 6,21,10
  71.         db    23,19,12, 4,26, 8
  72.         db    16, 7,27,20,13, 2
  73.         ;
  74. PC2_D        db    41,52,31,37,47,55
  75.         db    30,40,51,45,33,48
  76.         db    44,49,39,56,34,53
  77.         db    46,42,50,36,29,32
  78.         ;
  79.         ;******************************************
  80.  
  81.  
  82.         Public    E
  83.  
  84.         ;******************************************
  85.         ;
  86.         ; The E bit-selection table
  87.         ;
  88. E        db    32, 1, 2, 3, 4, 5
  89.         db     4, 5, 6, 7, 8, 9
  90.         db     8, 9,10,11,12,13
  91.         db    12,13,14,15,16,17
  92.         db    16,17,18,19,20,21
  93.         db    20,21,22,23,24,25
  94.         db    24,25,26,27,28,29
  95.         db    28,29,30,31,32, 1
  96.         ;
  97.         ;******************************************
  98.  
  99.  
  100.         Public    P
  101.  
  102.         ;******************************************
  103.         ;
  104.         ; P is a permutation on the selected
  105.         ; combination of the current L and key
  106.         ;
  107. P        db    16, 7,20,21
  108.         db    29,12,28,17
  109.         db     1,15,23,26
  110.         db     5,18,31,10
  111.         db     2, 8,24,14
  112.         db    32,27, 3, 9
  113.         db    19,13,30, 6
  114.         db    22,11, 4,25
  115.         ;
  116.         ;******************************************
  117.  
  118.  
  119.         Public    S
  120.  
  121.         ;******************************************
  122.         ;
  123.         ; The 8 selection functions
  124.         ;
  125. S        db    14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7
  126.         db     0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8
  127.         db     4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0
  128.         db    15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13
  129.         ;
  130.         db    15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10
  131.         db     3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5
  132.         db     0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15
  133.         db    13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9
  134.         ;
  135.         db    10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8
  136.         db    13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1
  137.         db    13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7
  138.         db     1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12
  139.         ;
  140.         db     7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15
  141.         db    13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9
  142.         db    10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4
  143.         db     3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14
  144.         ;
  145.         db     2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9
  146.         db    14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6
  147.         db     4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14
  148.         db    11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3
  149.         ;
  150.         db    12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11
  151.         db    10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8
  152.         db     9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6
  153.         db     4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13
  154.         ;
  155.         db     4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1
  156.         db    13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6
  157.         db     1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2
  158.         db     6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12
  159.         ;
  160.         db    13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7
  161.         db     1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2
  162.         db     7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8
  163.         db     2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11
  164.         ;
  165.         ;******************************************
  166.  
  167.  
  168.         Public    shifts
  169.  
  170.         ;******************************************
  171.         ;
  172.         ; Sequence shifts used for the key schedule
  173.         ;
  174. shifts        db    1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
  175.         ;
  176.         ;******************************************
  177.  
  178.  
  179.         Public    C C,D
  180.  
  181.         ;******************************************
  182.         ;
  183.         ; The C and D arrays used to calculate the
  184.         ; key schedule
  185.         ;
  186. C        db    28 dup(?)
  187. D        db    28 dup(?)
  188.         ;
  189.         ;******************************************
  190.  
  191.  
  192.         Public    KSL,KSH
  193.  
  194.         ;******************************************
  195.         ;
  196.         ; Left and right 24 bits of keys
  197.         ;
  198. KSL        dd    16 dup(?)
  199. KSH        dd    16 dup(?)
  200.         ;
  201.         ;******************************************
  202.  
  203.  
  204.         Public    LR,L,R
  205.  
  206.         ;******************************************
  207.         ;
  208.         ; The current clock divided into two halfs
  209.         ;
  210. LR        label    byte
  211. L        db    32 dup(?)
  212. R        db    32 dup(?)
  213.         ;
  214.         ;******************************************
  215.  
  216.  
  217.         Public    S0L,S1L,S2L,S3L,S4L,S5L,S6L,S7L
  218.         Public    S0H,S1H,S2H,S3H,S4H,S5H,S6H,S7H
  219.  
  220.         ;******************************************
  221.         ;
  222.         ; Tables that combine S and P operations
  223.         ;
  224. S0L        dd    64 dup(?)
  225. S1L        dd    64 dup(?)
  226. S2L        dd    64 dup(?)
  227. S3L        dd    64 dup(?)
  228. S4L        dd    64 dup(?)
  229. S5L        dd    64 dup(?)
  230. S6L        dd    64 dup(?)
  231. S7L        dd    64 dup(?)
  232.         ;
  233. S0H        dd    64 dup(?)
  234. S1H        dd    64 dup(?)
  235. S2H        dd    64 dup(?)
  236. S3H        dd    64 dup(?)
  237. S4H        dd    64 dup(?)
  238. S5H        dd    64 dup(?)
  239. S6H        dd    64 dup(?)
  240. S7H        dd    64 dup(?)
  241.         ;
  242.         ;******************************************
  243.  
  244. onebits48    dw    ?
  245. tmpE        db    48 dup(?)
  246.  
  247. stt        dw    S0L, S0H
  248.         dw    S1L, S1H
  249.         dw    S2L, S2H
  250.         dw    S3L, S3H
  251.         dw    S4L, S4H
  252.         dw    S5L, S5H
  253.         dw    S6L, S6H
  254.         dw    S7L, S7H
  255.         ;
  256. Ll        dd    ?
  257. Lh        dd    ?
  258. Rl        dd    ?
  259. Rh        dd    ?
  260. _Dl        dd    ?
  261. _Dh        dd    ?
  262. spstore        dw    ?
  263. bpstore        dw    ?
  264. saltme        dd    ?
  265.  
  266.         public    baseptr
  267. baseptr        dd    ?
  268.  
  269.         Ends
  270.  
  271. DummySeg    Segment    Para Use16
  272. _aa        dd    64*64 dup(?)
  273. _ab        dd    64*64 dup(?)
  274. _ac        dd    64*64 dup(?)
  275. _ad        dd    64*64 dup(?)
  276. DummySeg    Ends
  277.  
  278. BigSeg1        Segment Para Use16
  279. S0LS1L        dd    64*64 dup(?)
  280. S0HS1H        dd    64*64 dup(?)
  281. S2LS3L        dd    64*64 dup(?)
  282. S2HS3H        dd    64*64 dup(?)
  283. BigSeg1        Ends
  284.  
  285. BigSeg2        Segment    Para Use16
  286. S4LS5L        dd    64*64 dup(?)
  287. S4HS5H        dd    64*64 dup(?)
  288. S6LS7L        dd    64*64 dup(?)
  289. S6HS7H        dd    64*64 dup(?)
  290. BigSeg2        Ends
  291.  
  292.  
  293.  
  294.         .Code
  295.  
  296.         .386
  297.  
  298.         ASSUME    FS:BigSeg1,GS:BigSeg2
  299.  
  300.         Public    sixbitTOtf
  301.             Public    Fperm
  302.              Public    undoe
  303.                Public    toBA64
  304.         Public    xform
  305.         Public    Combiner
  306.         Public    DoSelfMod
  307.         Public    shortcrypt
  308.         Public    fsetkey
  309.  
  310. COMB        Macro    Row,Col
  311.         local    Loop0,Loop1
  312.         lea    si,Row
  313.         lea    bx,Col
  314.         mov    bp,si
  315.         mov    cx,64
  316. Loop1:
  317.         push    cx
  318.         mov    si,bp
  319.         mov    edx,[bx]
  320.  
  321.         rol    edx,16
  322.         shl    dl,2
  323.         rol    edx,16
  324.         shl    dl,2
  325.  
  326.         add    ebx,4
  327.         mov    cx,64
  328. Loop0:
  329.         lodsd
  330.  
  331.         rol    eax,16
  332.         shl    al,2
  333.         rol    eax,16
  334.         shl    al,2
  335.  
  336.         xor    eax,edx
  337.         stosd
  338.         loop    Loop0
  339.         pop    cx
  340.         loop    Loop1
  341.         Endm
  342.  
  343.  
  344.  
  345. Combiner    Proc    C Near
  346.         push    si
  347.         push    di
  348.         push    bp
  349.         push    es
  350.         mov    ax,BigSeg1
  351.         mov    es,ax
  352.         sub    di,di
  353.         COMB    S0L,S1L
  354.         COMB    S0H,S1H
  355.         COMB    S2L,S3L
  356.         COMB    S2H,S3H
  357.         mov    ax,BigSeg2
  358.         mov    es,ax
  359.         sub    di,di
  360.         COMB    S4L,S5L
  361.         COMB    S4H,S5H
  362.         COMB    S6L,S7L
  363.         COMB    S6H,S7H
  364.         ;
  365.         mov    bx,BigSeg1
  366.         mov    fs,bx
  367.         mov    bx,BigSeg2
  368.         mov    gs,bx
  369.         ;
  370.         pop    es
  371.         pop    bp
  372.         pop    di
  373.         pop    si
  374.         ret
  375. Combiner    Endp
  376.  
  377.  
  378.  
  379.         ;******************************************
  380.         ;
  381.         ; Convert unsl in six bits per byte format
  382.         ; to twenty-four bit contiguous format.
  383.         ; Return result
  384.         ;
  385. sixbitTOtf    Proc    C Near
  386.         ARG    sb:DWORD
  387.         mov    eax,DWord Ptr sb
  388.         shl    al,2
  389.         shl    ax,2
  390.         rol    eax,16
  391.         shl    al,2
  392.         shr    ax,2
  393.         ror    eax,4
  394.         mov    dx,ax
  395.         ror    eax,16
  396.         ret
  397. sixbitTOtf    Endp
  398.         ;
  399.         ;******************************************
  400.  
  401.  
  402.  
  403.         ;******************************************
  404.         ;
  405.         ; Final Permutation
  406.         ;
  407. Fperm        Proc    C Near block
  408.         push    si
  409.         push    di
  410.         cld
  411.         mov    ax,ds
  412.         mov    es,ax
  413.         lea    si,FP
  414.         mov    di,Word Ptr block
  415.         lea    bx,L
  416. @@Loop:
  417.         lodsb
  418.         xlat
  419.         stosb
  420.         cmp    si,Offset FP+64
  421.         jne    @@Loop
  422.         pop    di
  423.         pop    si
  424.         ret
  425. Fperm        Endp
  426.         ;                  
  427.         ;******************************************
  428.  
  429.  
  430.  
  431.         ;******************************************
  432.         ;
  433.         ; Inverse of E permutation
  434.         ;
  435. undoe        Proc    C Near
  436.         ARG    fromarr:WORD,toarr:WORD
  437.         push    si
  438.         push    di
  439.         mov    si,Word Ptr fromarr
  440.         mov    di,Word Ptr toarr
  441.         sub    cx,cx
  442. @@Loop:
  443.         mov    bx,cx
  444.         shr    bx,2 
  445.         shl    bx,1
  446.         mov    ax,bx
  447.         shl    bx,1
  448.         add    bx,ax
  449.         mov    ax,cx
  450.         and    ax,3
  451.         add    bx,ax
  452.         mov    al,[bx + si + 1]
  453.         mov    bx,cx
  454.         mov    [bx + di],al
  455.         inc    cx
  456.         cmp    cx,32
  457.         jne    @@Loop
  458.         pop    di
  459.         pop    si
  460.         ret
  461. undoe        Endp
  462.         ;******************************************
  463.  
  464.  
  465.  
  466.         ;******************************************
  467.         ;
  468.         ;
  469. toBA64        Proc    C Near
  470.         ARG    quarters:WORD,onebits64:WORD
  471.  
  472.         push    si
  473.  
  474.         mov    bx,ds
  475.         mov    es,bx
  476.         cld
  477.  
  478.         ;
  479.         mov    si,Word Ptr quarters ; get first quarter
  480.         mov    eax,[si]
  481.         push    eax
  482.         call    sixbitTOtf
  483.         add    sp,2
  484.  
  485.  
  486. Looper        =     0
  487.         rept    24
  488.          ror    eax,1
  489.          setc    [tmpE+Looper]
  490. Looper        =    Looper +1
  491.         endm
  492.  
  493.         mov    eax,[si+4]
  494.         push    eax
  495.         call    sixbitTOtf
  496.         add    sp,2
  497.  
  498.         rept    24
  499.          ror    eax,1
  500.          setc    [tmpE+Looper]
  501. Looper        =    Looper +1
  502.         endm
  503.  
  504.         lea    ax,L
  505.         push    ax
  506.         lea    ax,tmpE
  507.         push    ax
  508.         call    undoe
  509.         add    sp,4
  510.  
  511.         mov    eax,[si+8]
  512.         push    eax
  513.         call    sixbitTOtf
  514.         add    sp,2
  515.  
  516. Looper        =    0
  517.         rept    24
  518.          ror    eax,1
  519.          setc    [tmpE+Looper]
  520. Looper        =    Looper +1
  521.         endm
  522.  
  523.         mov    eax,[si+12]
  524.         push    eax
  525.         call    sixbitTOtf
  526.         add    sp,2
  527.  
  528.         rept    24
  529.          ror    eax,1
  530.          setc    [tmpE+Looper]
  531. Looper        =    Looper +1
  532.         endm
  533.  
  534.         lea    ax,R
  535.         push    ax
  536.         lea    ax,tmpE
  537.         push    ax
  538.         call    undoe
  539.         add    sp,4
  540.         ;
  541.         mov    ax,Word Ptr onebits64
  542.         push    ax
  543.         call    Fperm
  544.         pop    ax
  545.         ;
  546.         pop    si
  547.         ret
  548. toBA64        Endp
  549.         ;******************************************
  550.  
  551.  
  552.  
  553.  
  554.         ;******************************************
  555. BigMac1        Macro    Inner
  556.         Local    ModLow,ModHigh
  557.         mov    ebp,esi
  558.         xor    ebp,edi
  559.         and    ebp,eax
  560.  
  561.         mov    ebx,ebp
  562.         xor    ebx,esi
  563. ModLow:        xor    ebx,12345678h ;KSL+Inner*4
  564.  
  565.         xor    ecx,S0LS1L[bx]
  566.         xor    edx,S0HS1H[bx]
  567.         shr    ebx,16
  568.         xor    ecx,S2LS3L[bx]
  569.         xor    edx,S2HS3H[bx]
  570.  
  571.         xor    ebp,edi
  572. ModHigh:    xor    ebp,12345678h ;KSH+Inner*4
  573.  
  574.         xor    ecx,S4LS5L[bp]
  575.         xor    edx,S4HS5H[bp]
  576.         shr    ebp,16
  577.         xor    ecx,S6LS7L[bp]
  578.         xor    edx,S6HS7H[bp]
  579.         
  580.         .Data
  581.          dw    ModLow+3,ModHigh+3
  582.           .Code
  583.  
  584.         Endm
  585.         ;******************************************
  586.  
  587.  
  588.  
  589.         ;******************************************
  590. BigMac2        Macro    Inner
  591.         Local    ModLow,ModHigh
  592.         mov    ebp,ecx
  593.         xor    ebp,edx
  594.         and    ebp,eax
  595.  
  596.         mov    ebx,ebp
  597.         xor    ebx,ecx
  598. ModLow:        xor    ebx,12345678h ;KSL+Inner*4
  599.  
  600.         xor    esi,S0LS1L[bx]
  601.         xor    edi,S0HS1H[bx]
  602.         shr    ebx,16
  603.         xor    esi,S2LS3L[bx]
  604.         xor    edi,S2HS3H[bx]
  605.                       
  606.         xor    ebp,edx
  607. ModHigh:    xor    ebp,12345678h ;KSH+Inner*4
  608.  
  609.         xor    esi,S4LS5L[bp]
  610.         xor    edi,S4HS5H[bp]
  611.         shr    ebp,16
  612.         xor    esi,S6LS7L[bp]
  613.         xor    edi,S6HS7H[bp]
  614.  
  615.            .Data
  616.             dw    ModLow+3,ModHigh+3
  617.              .Code
  618.  
  619.         Endm
  620.         ;******************************************
  621.  
  622.  
  623.         .Data
  624. SelfModTab    Label    Word
  625.         .Code
  626.  
  627.         ;******************************************
  628.         ;
  629.                 ; Encrypt that block.
  630.         ;
  631.         ;
  632. xform        Proc    C Near
  633.         ;ARG    quarters:WORD,saltvalue:DWORD
  634.         cli
  635.         push    si
  636.         push    di
  637.  
  638.         mov    spstore,sp
  639.         mov    bpstore,bp
  640.  
  641.         ;mov    eax,saltvalue    ;not needed without the arg
  642.  
  643.            ;rol    eax,16
  644.            ;shl    al,2
  645.            ;rol    eax,16
  646.            ;shl    al,2
  647.  
  648.         sub    ecx,ecx
  649.         sub    edx,edx
  650.         sub    esi,esi
  651.         sub    edi,edi
  652.         sub    sp,sp
  653. @@Loop:
  654.         BigMac1    0
  655.                BigMac2    1
  656.                BigMac1    2
  657.                BigMac2    3
  658.                BigMac1    4
  659.                BigMac2    5
  660.                BigMac1    6
  661.                BigMac2    7
  662.                BigMac1    8
  663.                BigMac2    9
  664.                BigMac1    10
  665.                BigMac2    11
  666.                BigMac1    12
  667.                BigMac2    13
  668.                BigMac1    14
  669.                BigMac2    15
  670.  
  671.         xchg    ecx,esi
  672.         xchg    edx,edi
  673.  
  674.         inc    sp
  675.         cmp    sp,25
  676.                je    @@Quit
  677.                jmp    @@Loop
  678. @@Quit:
  679.         mov    baseptr,ebp
  680.         mov    bp,bpstore
  681.         mov    sp,spstore
  682.  
  683.         mov    eax,ecx
  684.         mov    ebx,edx
  685.         mov    ecx,esi
  686.         mov    edx,edi
  687.  
  688.           ;rol    eax,16
  689.            ;shr    al,2
  690.            ;rol    eax,16
  691.            ;shr    al,2
  692.        
  693.            ;rol    ebx,16
  694.            ;shr    bl,2
  695.            ;rol    ebx,16
  696.            ;shr    bl,2
  697.  
  698.            ;rol    ecx,16
  699.            ;shr    cl,2
  700.            ;rol    ecx,16
  701.            ;shr    cl,2
  702.  
  703.            ;rol    edx,16
  704.           ;shr    dl,2
  705.            ;rol    edx,16
  706.            ;shr    dl,2
  707.  
  708.            ;mov    si,Word Ptr quarters
  709.             ;mov    [si],eax
  710.            ;mov    [si+4],ebx
  711.            ;mov    [si+8],ecx
  712.            ;mov    [si+12],edx
  713.  
  714.         pop    di
  715.         pop    si
  716.         sti
  717.         ret
  718. xform        Endp
  719.         ;
  720.         ;******************************************
  721.  
  722.  
  723.         ;******************************************
  724.         ;
  725.         ; Self modify the transform to use new
  726.         ; Key schedule
  727.         ;
  728. DoSelfMod    Proc    Near
  729.         push    si
  730. Inner        =    0
  731.         rept    16
  732.         mov    eax,KSL+Inner*4
  733.         mov    ebx,KSH+Inner*4
  734.         mov    si,SelfModTab+Inner*4
  735.         mov    cs:[si],eax
  736.         mov    si,SelfModTab+Inner*4+2
  737.         mov    cs:[si],ebx
  738. Inner        =    Inner + 1
  739.         endm
  740.         pop    si
  741.         ret
  742. DoSelfMod    Endp
  743.         ;
  744.         ;******************************************
  745.  
  746.  
  747.         .DATA
  748. _out96        dd    4 dup(?)
  749.         .CODE
  750.  
  751.         ;******************************************
  752.         ;
  753. shortcrypt    Proc    C Near
  754.         ARG    out96:WORD,saltvalue:DWORD
  755.         push    si
  756.         mov    eax,saltvalue
  757.         ;push    eax
  758.         ;lea    ax,_out96
  759.         ;push    ax
  760.         call    xform
  761.         ;add    sp,6
  762.  
  763.         mov    si,out96
  764.         and    eax,1e781e78h
  765.         cmp    eax,[si]
  766.         jne    @@NoGood
  767.  
  768.         and    ebx,1e781e78h
  769.         cmp    ebx,[si+4]
  770.         jne    @@NoGood
  771.  
  772.         and    ecx,1e781e78h
  773.         cmp    ecx,[si+8]
  774.         jne    @@NoGood
  775.  
  776.         and    edx,1e781e78h
  777.         cmp    edx,[si+12]
  778.         jne    @@NoGood
  779.  
  780.         mov    ax,1
  781.         pop    si
  782.         ret
  783. @@NoGood:
  784.         mov    ax,0
  785.         pop    si
  786.         ret
  787. shortcrypt    Endp
  788.         ;
  789.         ;******************************************
  790.  
  791. fsetkey        Proc    C Near
  792.         ARG    key:WORD
  793.         push    si
  794.         push    di
  795.         mov    ax,ds
  796.         mov    es,ax
  797.         cld
  798.         sub    si,si
  799.         mov    bx,key
  800.         dec    bx
  801.         mov    cx,28
  802. @@Loop:
  803.         mov    al,PC1_C[si]
  804.         xlat
  805.         mov    C[si],al
  806.         mov    al,PC1_D[si]
  807.         xlat
  808.         mov    D[si],al
  809.         inc    si
  810.         loop    @@Loop
  811.         ;
  812.         sub    dx,dx
  813.         sub    bx,bx
  814. @@Loop1:
  815.  
  816.         movzx    cx,shifts[bx]
  817. @@Loop2:
  818.         push    cx
  819.         ;
  820.         mov    al,C[0]
  821.         mov    cx,27
  822.         lea    di,C
  823.         lea    si,C+1
  824.         rep    movsb
  825.         mov    C[27],al
  826.         ;
  827.         mov    al,D[0]
  828.         mov    cx,27
  829.         lea    di,D
  830.         lea    si,D+1
  831.         rep    movsb
  832.         mov    D[27],al
  833.         ;
  834.         pop    cx
  835.         loop    @@Loop2
  836.  
  837.         shl    bx,2
  838.         sub    eax,eax
  839.         sub    si,si
  840.         mov    cx,24
  841. @@Loop3:
  842.         mov    dl,PC2_C[si]
  843.          mov    di,dx
  844.         or    al,C[di-1]
  845.         ror    eax,1
  846.         inc    si
  847.         loop    @@Loop3
  848.  
  849.         ror    eax,8
  850.         shl    eax,4
  851.         shr    ax,2
  852.         rol    eax,16
  853.         rol    ax,2
  854.         rol    eax,16
  855.         mov    KSL[bx],eax
  856.  
  857.         sub    eax,eax
  858.         sub    si,si
  859.         mov    cx,24
  860. @@Loop4:
  861.         mov    dl,PC2_D[si]
  862.         mov    di,dx
  863.         or    al,D[di-28-1]
  864.         ror    eax,1
  865.         inc    si
  866.         loop    @@Loop4
  867.  
  868.         ror    eax,8
  869.         shl    eax,4
  870.         shr    ax,2
  871.         rol    eax,16
  872.         rol    ax,2
  873.         rol    eax,16
  874.         mov    KSH[bx],eax
  875.  
  876.         shr    bx,2
  877.         inc    bx
  878.         cmp    bx,16
  879.         je    @@Quit
  880.         jmp    @@Loop1
  881. @@Quit:
  882.         pop    di
  883.         pop    si
  884.         ret
  885. fsetkey        Endp
  886.  
  887.         End
  888.  
  889.  
  890.  
  891.  
  892.